<template>
	<u-skeleton rows="20" title rowsHeight="50rpx" :loading="isloading">

		<view class="p-[20rpx] stores">

			<!-- 配送  自取 card -->
			<view class="rounded-[20rpx] bg-[#fff] pb-[20rpx]" style="">
				<!-- 切换 -->
				<view v-if="hiddenTab" class="flex  bg-[#FFF1DF]">
					<view @click="change(index)" :key="index" class="
				flex-1 
				text-center 
				bg-[#999] 
				py-[30rpx]
				text-[#6e6e6e]
				text-[32rpx]
				rounded-t-[20rpx]
				changestylefirst" :class="changeStyle == index ? 'changestyle' :''" v-for="(item,index) in ['外卖配送','到店自取']">
						{{item}}
					</view>
				</view>
				<!-- 地址 -->

				<view v-if="changeStyle == 0" :class="hiddenTab == false ? 'pt-[20rpx]':''" class="flex justify-between mx-[20rpx]" @click="openAddressList">
					<view class="">

						<up-text
							v-if="defaultAddressList !== undefined && defaultAddressList !== null  && defaultAddressList?.outRange !== 1"
							color="#000000" size="17" :bold="true"
							:text="defaultAddressList?.address+ ' ' + defaultAddressList?.doorNum" lines="1"></up-text>


						<up-text
							v-if="defaultAddressList === undefined || defaultAddressList == null || defaultAddressList?.outRange === 1"
							color="#000000" size="17" :bold="true" text="请选择收货地址"></up-text>


						<up-text
							v-if="defaultAddressList !== undefined && defaultAddressList !== null && defaultAddressList?.outRange !== 1"
							color="#000000" size="13"
							:text="defaultAddressList?.realName + ' ' + defaultAddressList?.phone"
							margin="10rpx 0 0 0"></up-text>
						<up-text
							v-if="defaultAddressList ===undefined || defaultAddressList == null  || defaultAddressList?.outRange == 1"
							color="#000000" size="13" text="" margin="10rpx 0 0 0"></up-text>
					</view>
					<u-icon name="arrow-right" color="#999" size="18" class="mt-[5rpx]"></u-icon>
				</view>
				<!-- 送达时间 -->
				<view v-if="changeStyle == 0"
					class="text-[#6C6C6C] text-[26rpx] flex justify-between px-[20rpx] mt-[20rpx]">
					<view class="">立即送出</view>
					<!-- <view class="">大约17:36送达</view> -->
				</view>
				<!-- 到店自提 -->
				<view v-if="changeStyle == 1" class="mx-[20rpx]">
					<view class="">
						<up-text lines="1" color="#000000" size="17" :bold="true" :text="stores"></up-text>
					</view>
					<!-- 时间，电话选择 -->
					<view class="flex justify-between text-left mt-[20rpx]">
						<view class="flex-1">
							<view class="flex items-start">
								<view class="pt-[0rpx]">
									<image style="
								width: 31rpx; 
								height: 28rpx;
								margin-right: 0rpx; padding-bottom: 2rpx;" src="@/static/my/address/timeSvg.svg"></image>
								</view>

								<view class="">
									<view class="text-[26rpx]">
										自提时间
									</view>
									<view class="flex items-center  mt-[8rpx]" @click="openTime">
										<view class="text-left text-[26rpx] mr-[10rpx] text-[#c0c4cc]"
											:class="mode.prePickTime=='' ? 'textone':'texttwo'">
											{{mode.prePickTime || '请选择自提时间'}}
										</view>
										<u-icon name="arrow-right" size="14" color="#999999"></u-icon>

									</view>
								</view>
							</view>  

						</view>
						<view class="flex-none py-[10rpx]">
							<u-line direction="col" color="#efefef" margin=""></u-line>
						</view>

						<view class="flex-1 ml-[20rpx]">
							<view class="flex items-center">
								<image style="width: 31rpx; height: 28rpx;margin-right: 0rpx;"
									src="@/static/my/address/phoneSvg.svg"></image>
								<view class="text-[26rpx]">
									预留电话
								</view>
							</view>
							<view class="flex items-center   ml-[36rpx]">
								<view class="" style="width: 200rpx;">
									<up-input v-model="mode.prePhone" fontSize="26rpx" placeholder="请输入自提电话"
										border="none" type="number" maxlength="11"> </up-input>
								</view>
								<uni-icons type="compose" size="16" color="#999999"></uni-icons>

							</view>
						</view>

					</view>
				</view>
			</view>

			<!-- 支付方式 -->
			<view class="bg-[#fff] rounded-[20rpx] py-[20rpx] pl-[20rpx] my-[20rpx] flex justify-between items-center">
				<view class="text-[#000000] text-[30rpx] ">
					支付方式
				</view>
				<view class="">
					<u-radio-group v-model="mode.payType" placement="row">
						<u-radio :disabled="item.disabled" :customStyle="{marginRight:'20rpx'}" activeColor="#FE861C"
							v-for="(item, index) in radiolist" :key="index" :label="item.name" :name="item.type"
							@change="radioChange">
						</u-radio>
					</u-radio-group>
				</view>
			</view>

			<!-- 商品详情 -->

			<!-- 商品详情 -->
			<order-list style="z-index: 1;" :data="orderlist" @connections="goPhone()"
				@goStore="goStore()"></order-list>
			<!-- 订单信息 -->
			<view class="pr-[20rpx] pl-[20rpx]  bg-[#fff] rounded-[20rpx] mt-[20rpx]">
				<u--form labelPosition="left" :model="mode" class="splmu" style="background: #fff;">
					<u-form-item prop="" :borderBottom="true" @click="remarkShow = true">
						<view class="flex">

							<view class="flex-1">备注</view>
							<up-input :disabled="true" disabledColor="#fff" v-model="okremarks" placeholder="请输入备注"
								border="none" inputAlign="right"></up-input>
						</view>

					</u-form-item>
					<u-form-item prop="" :borderBottom="false" @click="showtableware = true">
						<view class="flex">

							<view class="flex-1">餐具数量</view>
							<up-input v-model="mode.dishNumber" :disabled="true" disabledColor="#fff"
								placeholder="请输入餐具数量" border="none" inputAlign="right"></up-input>
						</view>

					</u-form-item>
				</u--form>
			</view>
			<!-- 备注，餐具数量 -->
			<!-- 底部 foot-->
			<view class="h-[calc(var(--bottom-button-height)+25px)]"></view>
			<view class="button1" style="z-index: 10;">
				<view class="button">
					<view class="flex btinone">
						<!-- <view class="">
							<image class="imghui" src="../../static/homeimg/huangwm.png"
							 mode=""></image>
						</view> -->
						<view class="money">
							<view class="nummoney">
								<!-- .toFixed(2) -->
								￥{{Number(orderlist.totalPrice).toFixed(2)}}
							</view>
							<!-- <view class="">
								预估加配送费￥{{orderlist.deliveryFee}}元
							</view> -->
						</view>
					</view>
					<view v-if="showButton == true && orderOk== true" class="smallbuton" @click="sendOrder">
						提交订单
					</view>
					<view v-if="showButton == false || orderOk== false" class="smallbuton1" @click="notSeed()">
						提交订单
					</view>
				</view>
			</view>



			<!-- 备注弹出窗口 -->
			<u-popup :closeable="true" round="10" :show="remarkShow" @close="remarkClose">
				<view class="h-[70vh] p-[20rpx]">
					<view class="">
						<view class="">
							填写备注
						</view>
						<view class="py-[20rpx]">
							<view class="" style="position: relative;">
								<view class="">
									<u-textarea ref="textarea" v-model="mode.remarks" :maxlength="50"
										placeholder="请输入订单备注内容" @change="textarea"></u-textarea>
								</view>
								<view class="" style="position: absolute; right: 20rpx;bottom: 10rpx; color: #c0c4cc">
									{{mode.remarks.length>=50?50:mode.remarks.length}}/50
								</view>
							</view>


						</view>
					<!-- 	<view class="" style="padding: 20rpx 20rpx;
	  						position: fixed;
	  						bottom: 20rpx;width: calc(100% - 40rpx) ;   
							left-0;box-sizing: box-border;
	  						">
							<up-button @click="remarkSubmit" shape="circle" color="#FE861C">确认</up-button>
						</view> -->
						
						<view class="py-[0rpx] px-[20rpx] w-full fixed left-0 bottom-[40rpx] box-border height: 98rpx;">
							<up-button @click="remarkSubmit" :customStyle="{
								'border-radius': '20rpx',
								'font-size': '32rpx',
								'padding-left':'40rpx' ,
								'padding-right':'40rpx', 'height': '98rpx',
							}"
						 color="#FE861C">
								确认
							</up-button>
						</view>
					</view>
				</view>
			</u-popup>

			<!-- 地址列表窗口 -->
			<u-popup :closeable="true" :show="showAddress" @close="closeAddress" round="10">
				<view class="pb-[40rpx] stores">
					<view class="h-[700rpx] ">
						<view class="text-center pt-[20rpx]">
							选择收货地址
						</view>
						<view class="p-[20rpx] h-[ calc(100vh - 10rpx)]">
							<scroll-view @touchmove.stop.prevent style="height: 700rpx; " scroll-y="true">
								<u-radio-group v-model="radioAddressId" placement="column" @change="groupChange">
									<view v-for="(item,index) in AddressList" :key="index" class="">
										<view class="pt-[20rpx] flex justify-between">
											<view class="flex ">
												<view class=" ">
													<u-radio :disabled="item.outRange == 1 " activeColor="#FE861C"
														:name="item.id"></u-radio>
												</view>
												<view class="">
													<up-text class="" v-if="item.outRange == 0" :text="item.address "
														size="15" color="#010101"></up-text>
													<up-text class="" v-if="item.outRange == 1" :text="item.address "
														size="15" color="#AFAFAF"></up-text>
													<view class="pb-[20rpx] pt-[10rpx] text-[28rpx] "
														:class="item.outRange == 1?'text-[#AFAFAF]':'text-[#010101]'">
														{{item.realName}} {{item.phone}}
													</view>
												</view>
											</view>
											<view v-if="item.outRange == 0" @click="updateAddress(item)"
												class="ml-[40rpx]" >
												<u-icon name="edit-pen"></u-icon>
												<!-- <image class="w-[31rpx] h-[31rpx]" src="@/static/my/address/edit.svg"> -->
												<!-- </image> -->
											</view>
										</view>

										<u-line></u-line>

									</view>

								</u-radio-group>


								<view class="h-[calc(var(--bottom-button-height)+40px)]"></view>
								<view @click="goNewAddress()"
									class="pb-[40rpx] pt-[20rpx] px-[20rpx] w-full fixed left-0 bottom-[0rpx] box-border bg-[#fff]"
									style="width: 100%;">
									<!-- <up-button color="#FE861C" shape="circle" >新增地址</up-button> -->
									<up-button color="#FFEDDD" shape="circle"
										:customStyle="{height:' 96rpx',borderRadius:'20rpx',fontSize:'32rpx',color:'#FE861C'}">新增地址</up-button>
								</view>
							</scroll-view>
						</view>
					</view>
				</view>
			</u-popup>
			<!-- 时间选择窗口 -->
			<u-datetime-picker ref="datetimePickerRef" :show="showTime" v-model="mode.prePickTime" mode="time"
				:minHour="dataTimes" @cancel="openTime" @confirm="confirmTime"></u-datetime-picker>


			<!-- 餐具选择 -->
			<u-picker @cancel="showtableware = false" @confirm="tablewares" :show="showtableware"
				:columns="columnstableware"></u-picker>
		</view>
	</u-skeleton>
</template>

<script setup>
	import orderInfo from "@/components/orderInfo/orderInfo.vue"
	import orderList from "@/components/orderlist/orderlist.vue"
	// import NP from 'number-precision'
	import {
		ref,
		reactive,
		nextTick,
		watch
	} from 'vue'
	import {
		addreses, //4.1.4.1 收获地址列表
	} from "@/api/my.js"
	import {
		storenamedetal, //获取门店详情
	} from "@/api/home.js"
	import {
		orderpay, //4.4.7 提交订单
		createorder, //4.4.6 预下单
		balancePay, //4.4.8 立即付款-余额支付
		storecartdetals, //4.4.13 查看购物车
		deleteGoods, //4.4.15 清空购物车
		oredrDitils, //订单详情
		isVip //是否是会员
	} from "@/api/order.js"
	import {
		onLoad,
		onShow,
		onReady
	} from '@dcloudio/uni-app';
	import {
		useStore
	} from '@/stores/user.js'

	const disabledAddress = ref(false) //是否可以选择地址
	// const textarea = ref(null)
	onReady(() => {
		// 如果需要兼容微信小程序的话，需要用此写法
		// textarea.value.setFormatter((value) => {
		// 	if (value.length >= 50) {
		// 	  return value.substr(0, 50)
		// 	}else {
		// 	  return value
		// 	}
		// })

	})
	const textarea = (e)=>{
		console.log("e3",e.length);
		if(e.length >= 50){
			uni.showToast({
				title:'最多50个字哦~',
				icon:'none'
			})
		}
	}
	const showtableware = ref(false)
	const columnstableware = reactive([
		['无需餐具', '需要餐具，商家依据餐量提供', '1份', '2份', '3份', '4份', '5份', '6份', '7份', '8份', '9份', '10份以上']
	]);
	const tablewares = (e) => {
		// console.log("sdds",e.value[0]);
		mode.value.dishNumber = e.value[0]
		showtableware.value = false
	}
	const store = useStore();
	const isloading = ref(true)
	//备注餐具
	const mode = ref({
		orderId: '', //订单编号
		payType: 1, //付款方式：1-微信支付 2-余额支付
		remarks: '', //备注
		prePhone: '', //到店自取预留电话
		prePickTime: '', //到店自取时间
		dishNumber: '', //餐具数量备注 （商家按餐量提供，或  5份餐具）
	})
	const orderOk = ref(false)
	//订单信息
	const data = ref({
		distribution: '',
		address: '',
		name: '',
		phone: '',
		MerchantDistribution: '',
		orderNumber: '',
		time: '',
		paymentMethod: '',
		tablewareNumber: '',
		remark: ''
	})

	//订单商品
	const orderlist = ref({
		show: false,
		tradeName: "", //店铺名称
		distributionMode: "", //配送方式
		num: "", // 总订单数量
		orderList: [{
			goodsImages: "", //商品图片
			specification: "", // 规格，
			batchingIds: [], //配料
			singleorderNum: "", //单个商品数量   
			goodsName: "", //商品名称
			subtotalPrice: "", //当前单个商品总价
		}],
		balingCharge: "", //打包费
		deliveryFee: '', // 配送费
		servicePrice: '', //服务费
		totalPrice: '' //所有商品总价
	})
	const okremarks = ref()
	const shopId = ref() //店铺id
	const storeId = ref() //门店id
	const productList = ref([]) //商品详情列表
	const totalAmount = ref() //购物车中的总价
	const showAddress = ref(false) //地址弹窗显示隐藏
	const AddressList = ref() //地址列表
	const defaultAddressList = ref() //默认地址 addressId
	const addressId = ref() //默认地址id
	const changeStyle = ref(0) //配送方式切换
	const showTime = ref(false) //时间窗口
	const time = ref('') //自取时间
	const radioAddress = ref() //地址单选框的值
	const showOrderInfo = ref(false) //订单信息显示
	const isVIP = ref(false)
	const dataTimes = ref()
	const checkIn = ref(null)
	const radioAddressId = ref(null)
	const isOne = ref(true)
	onLoad((e) => {
		storeId.value = e.id //门店id
		// 进入预下单界面 首先判断是否有地址信息  没有地址信息则显示购物车列表  反之调用预下单接口
		// 

		// getAddressList() //获取地址
		setTimeout(() => {

			isNotVip()
		}, 500)
	})
	onShow(() => {
		// changeStyle.value = store.tabtype == 1 ?0 :1
        console.log("仓库",store.tabtype);
		dataTimes.value = new Date().getHours()
		getaddress()




		// console.log("当前时间",dataTimes);

	})

	const notSeed = () => {
		uni.showToast({
			title: '超出配送范围',
			icon: 'none'
		})
	}

	//判断是否是会员
	const isNotVip = () => {
		isVip({
			shopId: shopId.value
		}).then(res => {
			isVIP.value = res.result.isShopVip
			if (isVIP.value == false) {
				radiolist[1].disabled = true
			}
			// console.log("判断是否是会员", isVIP.value);
		})
	}
	//拨打电话
	const goPhone = (e) => {
		uni.makePhoneCall({
			phoneNumber: e
		})
		// console.log("拨打电话啊", e);
	}
	//跳转商户
	const goStore = () => {
		uni.navigateTo({
			url: '/page_index/storedetals?id=' + id.value
		})

	}

	//提交订单
	const sendOrder = () => {
		// console.log("提交订单");
		mode.value.orderId = mode.value.orderId + ""

		getCurrentTime() //获取下单时间
		if (changeStyle.value == 1) {
			if (mode.value.prePickTime == "" || mode.value.prePhone == "") {
				uni.showToast({
					title: '请填写收货时间/收货人电话',
					icon: 'none'

				})
				return
			} else {
				if (mode.value.dishNumber == '') {
					showtableware.value = true
				} else {
					orderpay({
						...mode.value
					}).then(res => {
						// console.log("提交订单", res);
						if (res.code == 200) {
							uni.redirectTo({
								url: '/page_order/submitanorder/payment/payment?orderId=' +
									mode.value.orderId + '&patType=' +
									mode.value.payType + '&totle=' +
									orderlist.value.totalPrice + '&createdAt=' + createdAt.value
							})
						}
					})
				}



			}

		} else {
			if (mode.value.dishNumber == '') {
				showtableware.value = true
			} else {
				orderpay({
					...mode.value
				}).then(res => {
					// console.log("提交订单", res);
					if (res.code == 200) {
						uni.redirectTo({
							url: '/page_order/submitanorder/payment/payment?orderId=' +
								mode.value.orderId + '&patType=' +
								mode.value.payType + '&totle=' +
								orderlist.value.totalPrice + '&createdAt=' + createdAt.value
						})
					}
				})
			}

		}

	}
	let change = (index) => {
		console.log("AddressList.value.length",AddressList.value.length);
		orderOk.value = false
		changeStyle.value = index
		if (index == 1) {
			orderlist.value.distributionMode = '到店自取'
			ReadyOrder()
		} else {
			orderlist.value.distributionMode = arrDeliveryType.value[0] == 1 ? '点老板配送' : arrDeliveryType.value[0] ==
				2 ? '商家配送' : ''
							
				ReadyOrder()
							
		
		}
		// console.log("配送方式切换", index);
	}
	//选择支付方式
	const radiovalue = ref();
	const radiolist = reactive([{
			name: '微信支付',
			disabled: false,
			type: 1
		},
		// {
		// 	name: '余额支付',
		// 	disabled: false,
		// 	type: 2
		// },
	])
	const radioChange = (n) => {
		mode.value.payType = n
		// console.log('radioChange', mode.value.payType);
	};

	//打开备注窗口
	let remarkShow = ref(false)
	let remarkOpen = () => {
		remarkShow.value = true
	}
	// 关闭备注窗口
	let remarkClose = () => {
		remarkShow.value = false
	}
	//提交备注
	let remarkSubmit = () => {
		okremarks.value = mode.value.remarks
		remarkShow.value = false
	}

	let getaddress = () => {
		isloading.value = true && isOne.value
		storeDetails() //门店详情
		addreses({
			storeId: storeId.value
		}).then(res => {
			if (res.code == 200) {
				AddressList.value = res.result //获取的地址列表
				if ((AddressList.value.length == 0 || AddressList.value[0].outRange == 1)   ) {
					addressId.value = null
					defaultAddressList.value = null
					showButton.value = false
					// 没有地址请求购物车，显示商品
					getShoppingCart()
					  console.log("没有地址请求购物车，显示商品");
				} else {
					 console.log("，显示商品");
					AddressList.value.forEach(item => {
						if (addressId.value == item.id) {
							defaultAddressList.value = item
							// console.log("显示商品");
						}
					})
					let check = checkIn.value === null ?
						(AddressList.value[0].outRange == 1 ? null : AddressList.value[0]) :
						checkIn.value
					if (check && AddressList.value.some(item => item.id == check.id)) {
						check = AddressList.value.find(item => item.id == check.id)
						radioAddress.value = check
						radioAddressId.value = check.id
						// console.log("没有地址请求购物车，显示商品111", check);
						defaultAddressList.value = radioAddress.value
						addressId.value = check.id
						setTimeout(() => {
							ReadyOrder()
						}, 500)
						// showAddress.value = false
						console.log('groupChange', addressId.value);
					} else if (AddressList.value[0].outRange != 1) {
						check = AddressList.value[0]
						radioAddress.value = check
						radioAddressId.value = check.id
						console.log(radioAddressId.value);
						console.log("没有地址请求购物车，显示商品");
						defaultAddressList.value = radioAddress.value
						addressId.value = check.id
						

					} else {
						console.log('else', addressId.value);
						setTimeout(() => {
							ReadyOrder()
						}, 500)
						addressId.value = null
						defaultAddressList.value = null
						showButton.value = false
						isloading.value = false
						isOne.value = false
					}
					// radioAddress.value = res.result[0] // 地址单选框的值
					// defaultAddressList.value = radioAddress.value
					// addressId.value = res.result[0].id
					// setTimeout(() => {
					// 	ReadyOrder()
					// }, 500)

				}
			}
		})
	}

	const ids = ref(0)
	let getAddressList = () => { //获取地址列表

		storeDetails() //门店详情
		addreses({
			storeId: storeId.value
		}).then(res => {
			if (res.code == 200) {
				// console.log("获取地址列表",defaultAddressList.value);
				AddressList.value = res.result //获取的地址列表


				if (AddressList.value.length == 0 || AddressList.value[0].outRange == 1) {
					// showOrderInfo.value = false
					// 没有地址请求购物车，显示商品
					getShoppingCart()
					// console.log("没有地址请求购物车，显示商品");
				} else {
					// showOrderInfo.value = true
					radioAddress.value = res.result[0] // 地址单选框的值
					// ids.value = res.result[0].id
					defaultAddressList.value = radioAddress.value
					addressId.value = res.result[0].id
					setTimeout(() => {
						ReadyOrder()
					}, 500)
				}
			}
		})
	}
	const goNewAddress = () => {
		uni.navigateTo({
			url: '/page_my/address/newaddress/newaddress'
		})
	}
	//打开地址列表
	let openAddressList = () => {
		showAddress.value = !showAddress.value
	}

	let closeAddress = () => {
		showAddress.value = !showAddress.value

	}
	let groupChange = (n) => {
		let item = AddressList.value.filter(item => item.id == n)[0]
		checkIn.value = item
		radioAddress.value = item
		radioAddressId.value = n
		console.log('aa', n);
		getaddress()
		showAddress.value = false
		
		
		
		// defaultAddressList.value = n
		// radioAddress.value = n
		// defaultAddressList.value =radioAddress.value
		// addressId.value = n.id
		// ids.value = n.id
		// setTimeout(() => {
		// 	ReadyOrder()
		// }, 500)
		// showAddress.value = false
		// console.log('groupChange', addressId.value);
	};


	//没有地址时请求购物车接口
	let getShoppingCart = () => {
		isloading.value = false
		isOne.value = false
		storecartdetals({
			storeId: storeId.value
		}).then(res => {

			if (res.code == 200 && res.result.cart.data.length > 0) {
				orderlist.value.orderList = []
				orderlist.value.balingCharge = 0
				orderlist.value.deliveryFee = 0 //配送费
				orderlist.value.totalPrice = res.result.cart.totalAmount
				orderlist.value.num = res.result.cart.data.length
                  orderlist.value.balingCharge = res.result.cart.packagePrice
				res.result.cart.data.forEach(item => { //商品列表
				console.log("胡军测试",item);
					orderlist.value.orderList.push({
						goodsImages: item.goodsImages,
						goodsName: item.goodsName,
						singleorderNum: item.num,
						specification: item.goodsStock.suk,
						subtotalPrice: item.subtotalPrice,
						batchingIds: item.batchingIds,
						
					})
					 console.log("胡军测试2", orderlist.value.orderList);
				})
			} else {
				uni.showToast({
					title: res.msg,
					icon: 'none'
				})
			}
		})
	}

	//预下单接口

	const showButton = ref(true)
	const ReadyOrder = () => {
         uni.showLoading({
         	title:"加载中..."
         })
		orderlist.value.orderList = []
		//获取购物车数据
		orderGoods.value = []
		getCart()
		//预下单参数
		const data = {
			storeId: Number(storeId.value), // 门店id
			deliverType: changeStyle.value == 0 ? arrDeliveryType.value[0] : 3, //配送方式  ，1-三方配送 2-商家自配送 3-到店自取
			addressId: addressId.value, //用户地址id，用户未填写地址时不传，但需传入用户当前位置信息，lng，lat
			orderGoods: orderGoods.value
		}
		// console.log("预下单data", data);
		setTimeout(() => {
			createorder(data).then(res => {
				isloading.value = false
				isOne.value = false
				showButton.value = true
				console.log("预下单data");
				if (res.code == 200) {
                      uni.hideLoading()
					// console.log("预下单", res);
					mode.value.orderId = res.result.orderIdStr
					orderlist.value.balingCharge = res.result.packagePrice //打包费
					orderlist.value.deliveryFee = res.result.totalDeliveryFee //配送费
					orderlist.value.servicePrice = 0, //服务费
						orderlist.value.totalPrice = res.result.totalPrice //所有商品总价
					res.result.orderGoods.forEach(item => { //商品列表
						orderlist.value.orderList.push({
							goodsImages: item.goodsImages[0], //商品图片
							goodsName: item.goodsName, //商品名称
							singleorderNum: item.goodsNum, //商品数量
							specification: item.goodsSpecSuk, //商品规格
							subtotalPrice: item.totalPrice, //当前商品价格
							batchingIds: item.batchings, //商品配料
						})

						isloading.value = false
						isOne.value = false
						orderOk.value = true
						// console.log("res.result.orderGoods", orderGoods.value);
					})
				}

			}).catch(err => {
				console.log("异常显示");
				getShoppingCart()
				showButton.value = false
				isloading.value = false
				isOne.value = false
			})
		}, 500)

	}

	//打开时间窗口
	let openTime = () => {
		showTime.value = !showTime.value
	}
	//确认时间选择
	let confirmTime = (e) => {
		mode.value.prePickTime = e.value
		showTime.value = !showTime.value
		// console.log('确认时间选择', time.value);
	}

	//预下单购物车
	const orderGoods = ref([])
	const id = ref()
	const phone = ref()
	const getCart = () => {
		storecartdetals({
			storeId: storeId.value
		}).then(res => {
			isloading.value = false
			isOne.value = false
			// console.log("购物车res", res);
			orderlist.value.num = res.result.cart.data.length
			// console.log("商品数量", orderlist.value.num);
			res.result.cart.data.forEach(item => { //商品列表
				// console.log("item", item);
				orderGoods.value.push({
					goodsId: item.id, //订单商品信息
					goodsNum: item.num, // 商品数量
					goodsSpec: { //商品规格信息，方便前端处理，就把选中的规格信息传入进去，必须包含id信息
						id: item.goodsStock.id,
						goodsId: item.id,
						stock: '',
						price: '',
					},
					batchings: item.batchingIds == null ? [] :
				[{ //商品配料信息，方便前端处理，就把选中的配料信息传入进去，没有选择配料，则不传
						batchingId: item.batchingIds[0].batchingId,
						batchingName: item.batchingIds[0].batchingName,
						price: item.batchingIds[0].price
					}]
				})
				// console.log("购物v车", orderGoods.value);
			})



		})
	}
	//获取门店详情，拿到配送方式
	const hiddenTab = ref(true)
	const arrDeliveryType = ref([])
	const stores = ref()
	const storeDetails = () => {
		storenamedetal({
			storeId: storeId.value,
			lat: store.lat,
			lng: store.lng,
		}).then(res => {
			shopId.value = res.result.shopId
			id.value = res.result.id
			phone.value = res.result.phone
			stores.value = res.result.storeName
			orderlist.value.tradeName = res.result.storeName //店铺名称
			arrDeliveryType.value = res.result.storeConfig.deliveryType //配送方式
			arrDeliveryType.value.sort(function(a, b) {
				return a - b;
			})
			if (arrDeliveryType.value.indexOf(3) == -1) {
				hiddenTab.value = false
			}
			orderlist.value.distributionMode = arrDeliveryType.value[0] == 1 ? '点老板配送' : arrDeliveryType.value[
				0] == 2 ? '商家配送' : ''
			// console.log("门店详情", res);
		})
	}

	//修改地址
	const updateAddress = (item) => {
		// console.log("修改地址", item);
		uni.navigateTo({
			url: '/page_my/address/editAddress/editAddress?id=' + item.id
		})
	}

	// 获取当前时间
	const createdAt = ref('')
	const getCurrentTime = () => {
		let yy = new Date().getFullYear();
		let mm = new Date().getMonth() + 1;
		let dd = new Date().getDate();
		let hh = new Date().getHours();
		let mf = new Date().getMinutes() < 10 ? '0' + new Date().getMinutes() : new Date().getMinutes();
		let ss = new Date().getSeconds() < 10 ? '0' + new Date().getSeconds() : new Date().getSeconds();
		createdAt.value = yy + '-' + mm + '-' + dd + ' ' + hh + ':' + mf + ':' + ss;

		// console.log("当前时间", createdAt.value)
	}
</script>

<style lang="scss" scoped>
	.splmu {
		::v-deep(.u-form-item__body__right__message) {
			text-align: right;
		}

	}

	::v-deep .u-form-item__body[data-v-42bac3de] {
		padding-top: 15px !important;
		padding-bottom: 14px !important;
	}

	.textone {

		color: #c0c4cc;
	}

	.texttwo {
		color: #303133;

	}

	::v-deep .u-cell__body.data-v-3fd6feca {
		padding: 10rpx 20rpx;
		align-items: start;
	}

	::v-deep .u-cell-group__title__text.data-v-014d39dc {
		font-size: 32rpx;
		line-height: 16px;
		color: #000000;
	}

	::v-deep .u-cell-group__title.data-v-014d39dc {
		padding: 20rpx 20rpx 10rpx 20rpx;
		font-weight: 500;
	}

	::v-deep .u-text.data-v-0a574502 {
		display: flex;
		flex-direction: row;
		align-items: center;
		flex-wrap: nowrap;
		flex: 1;
		width: 100%;
		padding-top: 2px;
	}

	.stores {
		--bottom-button-height: 50px;
	}

	.changestylefirst {
		background: linear-gradient(#F1F1F1, #FFFFFF);
	}

	.changestyle {
		color: #FE861C;
		background: linear-gradient(#FFF1DF, #FFFFFF);
	}

	.button1 {
		position: fixed;
		width: calc(100% - 0rpx);
		bottom: 0rpx;
		background: #f7f7f7;
		// border: #FE861C solid 1px;
		height: 98rpx;
	}

	.button {
		position: fixed;
		width: calc(100% - 40rpx);
		bottom: 40rpx;
		left: 20rpx;
		z-index: 555;
		height: 98rpx;
		background: #383838;
		border-radius: 49rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;

		.smallbuton {
			margin-right: 20rpx;
			font-size: 30rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #FFFFFF;
			background-color: #FE861C;
			padding: 16rpx 30rpx;
			text-align: center;
			border-radius: 36rpx;

		}

		.smallbuton1 {
			margin-right: 20rpx;
			font-size: 30rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #999999;
			background-color: #eaeaea;
			padding: 16rpx 30rpx;
			text-align: center;
			border-radius: 36rpx;

		}

		.btinone {
			padding-left: 40rpx;
		}

		.imghui {
			width: 88rpx;
			height: 66rpx;
		}

		.money {
			padding-left: 24rpx;
			font-size: 22rpx;
			font-family: PingFang SC;
			font-weight: 400;
			color: #FFFFFF;

			.nummoney {
				font-size: 36rpx;
				font-family: PingFang SC;
				font-weight: 700;
			}
		}
	}
</style>